package cn.aixuxi.notebank.service.impl;

import cn.aixuxi.notebank.entity.RoleEntity;
import cn.aixuxi.notebank.entity.SysUserRoleEntity;
import cn.aixuxi.notebank.mapper.RoleMapper;
import cn.aixuxi.notebank.mapper.SysUserRoleMapper;
import cn.aixuxi.notebank.service.IRoleService;
import cn.aixuxi.notebank.service.IUserRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * 类描述 角色服务实现
 *
 * @author ruozhuliufeng
 * @version 1.0
 * @date 2020/12/18 11:29
 */
@Service
public class UserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRoleEntity> implements IUserRoleService {


    /**
     * 功能描述:  判断用户是否拥有角色
     *
     * @param sysUserRoleEntity 角色信息
     * @return true-存在 false - 不存在
     * @author : ruozhuliufeng
     * @date : 2020/12/24 16:37
     */
    @Override
    public boolean isExist(SysUserRoleEntity sysUserRoleEntity) {
        QueryWrapper<SysUserRoleEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid", sysUserRoleEntity.getUid());
        queryWrapper.eq("role_id", sysUserRoleEntity.getRoleId());
        int count = this.count(queryWrapper);
        return count == 1;
    }
}
